#!/usr/bin/env node

const koa = require('koa'),
  bodyparser = require('koa-bodyparser'),
  image = require('./routers/image_router'),
  json = require('koa-json'),
  logger = require('koa-logger'),
  cors = require('koa2-cors'),
  koabody = require('koa-body'),
  // jwt = require('koa-jwt'),
  // jwt2 = require('jsonwebtoken'),
  // {JWT_KEY} = require('./lib/constant.js'),
  // express = require('express'),
  app = new koa({
    debug: true,
    http: true,
    key: '/usr/local/cert/www.h5weixin.club.key',
    cert: '/usr/local/cert/www.h5weixin.club.crt'
  });

app.use(json());
app.use(logger());
app.use(cors({
  "Access-Control-Allow-Origin": "*"
}));
// app.use(jwt({secret:JWT_KEY}).unless({path:/\/api\/users\/login$/}));
app.use(koabody({
  multipart: true,
  formidable: {
    maxFileSize: 200 * 1024 * 1024    // 设置上传文件大小最大限制，默认2M
  }
}))
app.use(bodyparser({ enableTypes: ['json', 'form', 'text'] }));
// app.use(async(ctx,next)=>{
//   let token = ctx.header.authorization;
//   if(typeof token !== 'undefined'){
//     token = token.split(' ')[1];
//     let user = jwt2.verify(token,JWT_KEY);
//     ctx.userId = user.id;
//   }

//   await next();
// });
// app.use(tasks.routes());
app.use(image.routes())
app.listen(1025);
